package com.zyh.answer.controller;

import com.zyh.answer.domain.AnalyzeDataObj;
import com.zyh.answer.domain.UserAnswer;
import com.zyh.answer.service.UserAnswerService;
import com.zyh.common.core.controller.BaseController;
import com.zyh.common.core.domain.AjaxResult;
import com.zyh.record.service.ExamRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Objects;

/**
 * 用户答题记录
 *
 * @author ZYH
 * @version 1.0
 * @date 2025-02-23
 */
@RestController
@RequestMapping("/answer/answer")
public class UserAnswerController extends BaseController {

    @Autowired
    private UserAnswerService userAnswerService;

    @Autowired
    private ExamRecordService examRecordService;

    /**
     * 添加答题记录
     *
     * @param userAnswer
     * @return
     */
    @PostMapping("/addAnswer")
    public AjaxResult addAnswer(@RequestBody UserAnswer userAnswer) {
        logger.info("addAnswer入参->{}", userAnswer);
        return examRecordService.addAnswer(userAnswer);
    }

    /**
     * 获取之前的测评进度
     *
     * @param paperId
     * @return
     */
    @GetMapping("/resumeAssessment/{paperId}")
    public AjaxResult resumeAssessment(@PathVariable("paperId") Long paperId) {
        logger.info("resumeAssessment入参->{}", paperId);
        return userAnswerService.resumeAssessment(paperId);
    }

    /**
     * 获取分数
     *
     * @param paperId
     * @return
     */
    @GetMapping("/generalScore/{paperId}")
    public AjaxResult generalScore(@PathVariable("paperId") Long paperId,
                                   @RequestParam("delFlag") String delFlag,
                                   @RequestParam(value = "recordId" , required = false) Long recordId) {
        logger.info("generalScore入参->{},{},{}", paperId, delFlag,recordId);
        AnalyzeDataObj analyzeDataObj = userAnswerService.getScore(paperId, delFlag, recordId);
        return Objects.nonNull(analyzeDataObj) ?
                AjaxResult.success("分数处理完成", analyzeDataObj) : AjaxResult.error("分数处理失败");
    }
}
